package com.pcs.controller;




import java.util.Date;

import com.jfinal.core.Controller;
import com.pcs.common.EasyPage;
import com.pcs.model.Blog;

public class BlogController extends Controller {
	public void index() {
		
		EasyPage easyPage = new EasyPage();
		easyPage.setTotal(Blog.blogDao.paginate(getParaToInt("page"), 10).getTotalRow());
		easyPage.setRows(Blog.blogDao.paginate(getParaToInt("page"), 10).getList());
		renderJson(easyPage);
	}
	
	public void _index() {
		
		EasyPage easyPage = new EasyPage();
		easyPage.setTotal(Blog.blogDao._paginate(getParaToInt("page"), 10).getTotalRow());
		easyPage.setRows(Blog.blogDao._paginate(getParaToInt("page"), 10).getList());
		renderJson(easyPage);
	}
	
	
	
	public void save() {
		Blog blog = new Blog();
		blog.set("title", getPara("title"));
		blog.set("content", getPara("content"));
		blog.set("createdate", new Date());
		blog.set("status", "A");
		blog.save();
		
		redirect("/page/blog.html");
		//renderText("hello");
		//Blog.blogDao.setAttrs(blog);
		
	}
	
	public void edit() {
		setAttr("blog", Blog.blogDao.findById(getParaToInt()));
		
		renderText("hello");
	}
	
	
	public void update() {
		Blog blog = new Blog();
		blog.set("title", getPara("title"));
		blog.set("content", getPara("content"));
		blog.set("createdate", new Date());
		blog.set("status", "A");
		blog.update();
		
		renderText("hello");
	}
	
	public void _update() {
		Blog blog = new Blog();
		blog.set("id", getPara("id"));
		blog = Blog.blogDao.findById(getPara("id"));
		blog.set("status", "A");
		
		blog.update();
		
		renderText("hello");
	}
	
	
	
	public void delete() {
		
		Blog blog = new Blog();
		blog.set("id", getPara("id"));
		blog.set("status", "I");
		blog.update();
		
		renderText("hello");
	}
	
	public void remove() {
		Blog.blogDao.deleteById(getPara("id"));
		
		renderText("hello");
	}
}
